<?php

namespace controller;

use service\ToolsService;
use think\Db;

/**
 * 基础接口类1
 * Class BasicApi
 * @package controller
 */

class BasicIndex extends BasicApi
{
    protected $id;

    protected $user;
    protected $commonService;
    public function __construct()
    {
        parent::__construct();
        $this->commonService = getMemberFree();
        header('Access-Control-Allow-Origin:*');
    }




    public function squarePoint($lng, $lat, $distance = 0.5)
    {


        $dlng = 2 * asin(sin($distance / (2 * EARTH_RADIUS)) / cos(deg2rad($lat)));

        $dlng = rad2deg($dlng);


        $dlat = $distance / EARTH_RADIUS; //EARTH_RADIUS地球半径

        $dlat = rad2deg($dlat);


        return array(

            'left-top' => array('lat' => $lat + $dlat, 'lng' => $lng - $dlng),

            'right-top' => array('lat' => $lat + $dlat, 'lng' => $lng + $dlng),

            'left-bottom' => array('lat' => $lat - $dlat, 'lng' => $lng - $dlng),

            'right-bottom' => array('lat' => $lat - $dlat, 'lng' => $lng + $dlng)

        );
    }



function distance($lat1, $lon1, $lat2,$lon2,$radius = 6371.137)
    {
        $rad = floatval(M_PI / 180.0);

        $lat1 = floatval($lat1) * $rad;
        $lon1 = floatval($lon1) * $rad;
        $lat2 = floatval($lat2) * $rad;
        $lon2 = floatval($lon2) * $rad;

        $theta = $lon2 - $lon1;

        $dist = acos(sin($lat1) * sin($lat2) + cos($lat1) * cos($lat2) * cos($theta));

        if ($dist < 0 ) {
            $dist += M_PI;
        }
        return $dist = $dist * $radius;
    }

    function getDistance($lat1, $lng1, $lat2, $lng2, $len_type = 1, $decimal = 2)
    {

        // 将角度转为狐度  
    $radLat1 = deg2rad($lat1);// deg2rad()函数将角度转换为弧度
    $radLat2 = deg2rad($lat2);
    $radLng1 = deg2rad($lng1);
    $radLng2 = deg2rad($lng2);

    $a = $radLat1 - $radLat2;
    $b = $radLng1 - $radLng2;

    $s = 2 * asin(sqrt(pow(sin($a / 2), 2)+cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))) * 6378.137;
//dump($s);
    return $s;
    }
}